package com.mzj.saas.mservice.eligible.repository;

import com.mzj.saas.mservice.eligible.entity.ApplyAudit;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface ApplyAuditRepository extends PagingAndSortingRepository<ApplyAudit, Long>, JpaSpecificationExecutor<ApplyAudit> {
    List<ApplyAudit> findByApplyId(Long applyId);

    List<ApplyAudit> findByCurrentAuditId(String currentAuditId);

    List<ApplyAudit> findByApplyIdAndAuditStatus(Long applyId, Integer auditStatus);

    ApplyAudit findByApplyIdAndAuditStatusAndCurrentAuditId(Long applyId, Integer auditStatus, String currentAuditId);

    @Modifying
    @Query(value = "SELECT * FROM saas_house_apply_audit WHERE apply_id = ?1 AND audit_status IN (2,3) AND current_audit_id = ?2", nativeQuery = true)
    List<ApplyAudit> findApproved(Long applyId, String currentAuditId);

    List<ApplyAudit> findByAuditStatusAndCurrentAuditId(Integer auditStatus, String currentAuditId);

    List<ApplyAudit> findByApplyIdAndCurrentAuditIdAndAuditStatus(Long applyId, String currentAuditId, Integer auditStatus);

    List<ApplyAudit> findByOrgAreaId(Long orgAreaId);
}
